local skill = fk.CreateSkill {
    name = "gongnan__enemy_at_the_gates_skill",
  }
  
  skill:addEffect("cardskill", {
    prompt = "#emo__enemy_at_the_gates_skill",
    target_num = 1,
    mod_target_filter = function(self, player, to_select, selected, card)
      return to_select ~= player
    end,
    target_filter = Util.CardTargetFilter,
    on_effect = function(self, room, effect)
      local player = effect.from
      local target = effect.to
      effect.extra_data = effect.extra_data or {}
      local source_cards = effect.extra_data.fromIds or {} -- 额外的来源牌
      effect.extra_data.own_cards = effect.extra_data.own_cards or {}
      local n = 4 + (effect.extra_data.num or 0) -- 额外亮出数
      if n < 1 and #source_cards == 0 then return end
      local cards = #source_cards > 0 and source_cards or room:getNCards(n, effect.extra_data.fromArea or "top")
      effect.extra_data.EMOenemy_at_the_gates = cards
      -- 在此移动时机，可以修改亮出牌的信息……
      room:moveCardTo(cards, Card.Processing, nil, fk.ReasonJustMove, self.name, nil, true, player)
      cards = effect.extra_data.EMOenemy_at_the_gates
      local rest = {}
      while not target.dead do
        cards = table.filter(cards, function (id)
          return room:getCardArea(id) == Card.Processing
        end)
        if #cards == 0 then break end
        room:delay(600)
        local cid = table.remove(cards, 1)
        local card = Fk:getCardById(cid)
        if card.trueName == "slash" and player:canUseTo(card, target, {bypass_distances = true, bypass_times = true}) then
          local use = UseCardData:new {
            card = card,
            from = player,
            tos = {target},
            extraUse = true,
          }
          room:useCard(use)
          local useParent = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
          if useParent then
            local use_data = useParent.data
            use_data.extra_data = use_data.extra_data or {}
            use_data.extra_data.enemy_at_the_gates_Info = use_data.extra_data.enemy_at_the_gates_Info or {}
            table.insert(use_data.extra_data.enemy_at_the_gates_Info, {card})
          end
        else
          local useParent = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
          if useParent then
            local use_data = useParent.data
            use_data.extra_data = use_data.extra_data or {}
            use_data.extra_data.rest = use_data.extra_data.rest or {}
            table.insert(use_data.extra_data.rest, cid)
          end
        end
      end
    end,
  })
  
  
  
  return skill
  